<?php 
	require_once ("../../config.php");
?>
<html>
<head>
<title>ITControl Masisa</title>
<link rel="stylesheet" href="/itcontrol/com/visual/style.css">
</head>
	<body>
		<div id="div_navbar" align="right">
			<?php 
				# Add div with Navbar
				echo navbar();
			?>
		</div>
		<div id="div_menu" align="left">
			<?php 
				# Add div with Menu						
				echo menu();
			?>
		</div>
		<div id="div_form" align="left">
			<form id="form_main" name="form_main" method="post" action="unit_add_db.php">
				<?php 
					# Add Main Form. If return is empty, so it's a new insertion, and the input boxes are empty.
					# Else, it's a retry and the input boxes have some values, but not all values. So retry
					# insertion and shows message alerting for empty input boxes.
						
					# Get the return value
					$return = $_GET["return"];									
					
					# Array contains that fields that we'll use
					$fields[0] = "nameUnit";
					$fields[1] = "cnpj";	
					
					# Array contains the Alias of fields
					$namefields[0] = "Unidade";
					$namefields[1] = "CNPJ";
					
					# Array contains that fields that we'll (Option Button)
					$fieldsOpt[0] = "city";
					
					# Array contains the Alias of fields (Option Button)
					$namefieldsOpt[0] = "Cidade";
					
					# 
					$tableOpt[0] = "tb_uf";
					
					#
					$typeOpt[0] = "uf";
					
					# If return doesn't are empty, reload the page with the previous data on input boxes
					# and shows a warning message. Else load page with blank input boxes.
					if(!empty($return)){
						
						# Transform return into a array
						$values = explode(",", $return);
							
						# Put $values[2] in $on. Clear $values[2]
						$on[0] = $values[2];
						$values[2] = null;
						
						echo loadDataOpt("tb_unit", "unit", "add", $fields, $namefields, $tableOpt, $typeOpt, "add", $fieldsOpt, $namefieldsOpt, $values, $on);
					}else{
						echo dataOpt("tb_unit", "unit", "add", $fields, $namefields, $tableOpt, $typeOpt, "add", $fieldsOpt, $namefieldsOpt);
					}
					
					echo menuaction("unit", "add");
				?>
			</form>
		</div>
	</body>
</html>